/**
 * Copyright © 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.cms.dyn.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.modules.cms.column.entity.CmsColumn;
import com.jeeplus.modules.cms.contenttype.entity.CmsContentType;
import com.jeeplus.modules.cms.dm.entity.CmsDynamic;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 动态内容Entity
 *
 * @author Sawyer
 * @version 2020-11-26
 */
@Getter
@Setter
@ToString
public class CmsContentsDyn extends DataEntity<CmsContentsDyn> {

    private static final long serialVersionUID = 1L;

    @NotNull(message = "栏目编号不能为空")
    private CmsColumn column;
    private CmsContentType contentType;

    @NotNull(message = "动态表单编号不能为空")
    private CmsDynamic dynamic;
    @ExcelField(title = "标题，冗余JSON数据中的k_title或k_name", align = 2, sort = 4)
    private String title;
    @ExcelField(title = "置顶权重", align = 2, sort = 5)
    private Integer topWeight;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ExcelField(title = "置顶期限", align = 2, sort = 6)
    private Date topDate;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ExcelField(title = "发布时间", align = 2, sort = 7)
    private Date releaseDate;
    @ExcelField(title = "点击数", align = 2, sort = 8)
    private Integer hits;
    @ExcelField(title = "JSON数据", align = 2, sort = 9)
    private String data;

    /**
     * 主Map，用于存储dynamic.dataModel中的key和value的第一段中文名称，供前端使用
     */
    private Map<String, String> mainMap;

    /**
     * 表单类型Map，用于存储dynamic.dataModel中的key和value的第二段表单类型，供前端使用
     */
    private Map<String, String> typeMap;

    /**
     * 数据值Map，用于存储data转换后的Map，供前端使用
     */
    private Map<String, Object> dataMap;

    /**
     * 所属站点,不在界面上显示，隐性关联
     */
    private String siteId;

    public CmsContentsDyn() {
        super();
        this.setIdType(IDTYPE_AUTO);
        this.setMainMap(new LinkedHashMap<>());
        this.setTypeMap(new HashMap<>());
        this.setDataMap(new HashMap<>());
    }

    public CmsContentsDyn(String id) {
        super(id);
    }

    /**
     * 初始化数据
     */
    public void init() {
        this.setHits(0);
        this.setTopWeight(0);
    }
}
